source ~/.bash_profile
# 服务器启动脚本
cd /root/app/lq_fucker/
#获取最新的调度包
wget -N http://jump-inner.liang-xin.com:8999/lx-job-client-1.0.jar  -P ./
#获取最新的requirements.txt
wget -N http://jump-inner.liang-xin.com:8998/requirements.txt  -P ./

wget -N http://jump-inner.liang-xin.com:8998/ssh.tar.gz  -P ./

#备份当前项目到本地
current_branch=`git symbolic-ref --short HEAD`
current_time=`date +%Y%m%d-%H%M`
git branch $current_branch$current_time
#git push origin $current_branch$current_time
git pull

#标识为测试环境，需要从宿主机的环境变量中取。避免出错
lq_env=${lq_env=test}
#标识 docker_name
docker_name=lq_${lq_env}_fucker
#获取ip地址
ip=`ifconfig |grep -A 1 -w "^eth0"  |grep inet |awk '{print$2}'`


#启动docker需要配置相关参数
#HOST_IP 宿主机ip
#mount_path 挂载宿主机磁盘路径
#lq_env 运行环境



docker ps | grep ${docker_name} | awk '{print $1}' | xargs -t docker stop
docker ps -a | grep ${docker_name} | awk '{print $1}' | xargs docker rm
docker images | grep 'none' | awk '{print $3}' | xargs docker rmi -f
docker build -t ${docker_name}':1.0' -f Dockerfile_script .


#映射端口  web_api 为 8088:8088   script为 5051:5050
docker images | grep -w ${docker_name} | awk '{print $3}' | xargs docker run -d -it  \
-e HOST_IP="${ip}"  \
-e lq_env="${lq_env}"  \
-e fucker_env=${fucker_env:="dev"} \
-e dingding_token="${dingding_token}"  \
-p 5050:5050 \
--restart=always  \
-v /etc/localtime:/etc/localtime:ro  \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /usr/bin/docker:/usr/bin/docker \
-v '/mnt/fucker_logs/':'/fucker/fucker_logs/' \
--name=${docker_name}

